<template>
  <a-modal
    :visible="visible"
    :title="title"
    :width="900"
    @cancel="() => { $emit('cancel') }"
  >

    <a-row style="color: #000">

      <template v-if="type === 'student'">
        <a-col :md="8" :sm="12" style="margin-bottom:10px;">
          <a-col :span="8">院系：</a-col>
          <a-col :span="15">
            <a-select style="width:100%;" allowClear @change="yxChange" v-model="searchForm.ssyxm" showSearch :filterOption="filterOption">
              <a-select-option v-for="i in selectMenu.yxList" :key="i.id" :value="i.dwh">{{ i.dwh }} {{ i.dwmc }}</a-select-option>
            </a-select>
          </a-col>
        </a-col>
         <a-col :md="8" :sm="12" style="margin-bottom:10px;">
          <a-col :span="8">专业：</a-col>
          <a-col :span="15">
            <a-select style="width:100%;" allowClear v-model="searchForm.sszym" showSearch :filterOption="filterOption">
              <a-select-option v-for="(i,index) in selectMenu.zyList" :key="index" :value="i.zyh">{{ i.zyh}} {{ i.zymc }}</a-select-option>
            </a-select>
          </a-col>
        </a-col>
        <a-col :md="8" :sm="12" style="margin-bottom:10px;">
          <a-col :span="8">年级：</a-col>
          <a-col :span="15">
            <a-select style="width:100%;" allowClear v-model="searchForm.sznj">
              <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
            </a-select>
          </a-col>
        </a-col>
        <a-col :md="8" :sm="12" style="margin-bottom:10px;">
          <a-col :span="8">学号：</a-col>
          <a-col :span="15">
            <a-input v-model="searchForm.xh"/>
          </a-col>
        </a-col>
        <a-col :md="8" :sm="12" style="margin-bottom:10px;">
          <a-col :span="8">姓名：</a-col>
          <a-col :span="15">
            <a-input v-model="searchForm.xm"/>
          </a-col>
        </a-col>
      </template>

      <!-- <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>-->
      <a-button type="primary" @click="exportExcel">导出听课学生名单</a-button>
    </a-row>
    <s-table
      ref="table"
      size="default"
      rowKey="id"
      :columns="columns"
      :data="loadData"
      :pagination="{ pageSize: 10 }"
    >
    </s-table>
    <a-button slot="footer" type="primary" @click="() => { $emit('cancel') }">关闭</a-button>

    <!--<a-textarea v-if="type === 'teacher'" v-model="teacherNote" placeholder="任课教师说明（500字以内）" :maxlength="500" :rows="4"/>-->
  </a-modal>

</template>

<script>
import { mapState } from 'vuex'
import { STable } from '~'
import DetailList from '~/tool/DetailList'
const DetailListItem = DetailList.Item

export default {
  name: 'studentsList',
  props: ['title', 'visible', 'yxList', 'type', 'editId'],
  components: {DetailList, DetailListItem, STable},
  data () {
    return {
      searchForm: {},
      selectMenu: {},
      columns: [
        {
          title: '学号',
          dataIndex: 'xsxh'
        },
        {
          title: '姓名',
          dataIndex: 'xm'
        },
        {
          title: '培养单位',
          dataIndex: 'dwmc'
        },
        {
          title: '所属专业',
          dataIndex: 'zymc'
        },
        {
          title: '是否选择培养计划课程',
          dataIndex: 'sfxzpyjh'
        },
        {
          title: '修课状态',
          dataIndex: 'xkztmc'
        }
      ],
      loadData: parameter => {
        parameter.pageNum = parameter.pageNo
        let params = Object.assign(this.searchForm, parameter)
        params.pkxxId = this.pkxxId
        return this.$api.cultivate.attendStudentList(params).then(res => {
          return {
            data: res.data.rows,
            pageNo: parameter.pageNo,
            pageSize: parameter.pageSize,
            totalPage: Math.ceil(res.data.total / parameter.pageSize),
            totalCount: res.data.total
          }
        }).catch(() => {
          return {
            data: [],
            pageNo: 1,
            pageSize: 10,
            totalPage: 1,
            totalCount: 0
          }
        })
      }
    }
  },
  computed: {
    ...mapState({
      TYPE0126: state => state.app['TYPE0126']
    })
  },
  created () {
    this.$store.dispatch('app/setDictionary', 'TYPE0126')
    let allRequest = [
      this.$api.base.collegeAll()
    ]
    Promise.all(allRequest).then(res => {
      this.selectMenu = {
        yxList: res[0].data
      }
    })
  },
  methods: {
    data () {
      return {
        pkxxId: ''
      }
    },
    filterOption (value, op) {
      return op.componentOptions.children[0].text.indexOf(value) !== -1
    },
    yxChange (code) {
      this.$set(this.searchForm, 'sszym', '')
      if (code) {
        this.$api.base.majorAll({lsdwh: code}).then(res => {
          this.$set(this.selectMenu, 'zyList', res.data)
        })
      } else {
        this.$set(this.selectMenu, 'zyList', [])
      }
    },
    exportExcel () {
      let params = {
        pkxxId : this.pkxxId
      }
      this.$export('/foster/tkxsmd/tkxsmdExport', {
        ...params
      })
    }
  }
}
</script>

<style>

</style>
